import { toggleHeight } from '@/utils/dom';

const seriesRegExp = /^cq\-accordion\-\-s\d+n\d+$/;

class Accordion {
	el = null; // 元素
	series = []; // 组件系列名
	constructor(params) {}
}

export default {
	setup: false, // 是否已开启默认设置
	create(params) {
		return new Accordion(params);
	},
	setupDefault() {
		this.setup = true;
		const accordionList = document.querySelectorAll('.cq-accordion');
		for (let item of accordionList) {
			const lable = item.querySelector('.cq-accordion--lable');
			if (!lable) continue;
			lable.addEventListener('click', function (e) {
				const parentNode = this.parentNode;
				const contentNode = parentNode.querySelector('.cq-accordion--content');
				if (contentNode) {
					toggleHeight(contentNode, {
						callback(height) {
							if (height) {
								parentNode.classList.add('click');
							} else {
								parentNode.classList.remove('click');
							}
						},
					});
				}
			});
		}
	},
};
